package softtech.apps.callblocker;

import java.util.ArrayList;
import java.util.List;

import softtech.apps.utility.ApplicationConstants;
import softtech.apps.callblocker.adapter.AdapterBlackList;
import softtech.apps.callblocker.adapter.AdapterExceptionItem;
import softtech.apps.callblocker.model.BlackListItem;
import softtech.apps.callblocker.model.DatabaseHanler;
import softtech.apps.callblocker.model.Setting;
import android.app.Activity;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.ViewFlipper;

//import softtech.apps.callblocker.

public class ActivityShowBlackListItem extends Activity {

	final String TAG = "Activity Show BlackListItem";
	final Context context = this;
	final int PICK_CONTACT = 1;
	final int PICK_CONTACT_EXCEPTION = 2;
	Dialog dialog;
	Setting sett;
	/**
	 * View fliper
	 */
	Button btnBlackList, btnException;
	ViewFlipper vflipMain;

	/**
	 * page exception
	 */
	Button btnAddExceptionItem;
	EditText edtAddPhNumer;
	ListView lvExceptionListItem;
	AdapterExceptionItem adapterException;

	/**
	 * Animation of vflipMain
	 */
	Animation slide_in_left, slide_out_right;

	/**
	 * Selected position of vflipMain
	 */
	int currentPage;

	/**
	 * editText to enter phone or name to search
	 */
	private EditText edtAddPhoneNumber;

	/**
	 * ImageView if click this show dialog Add number into BlackListItem
	 */
	private ImageView imgAdd;

	/**
	 * ListView containt BlackListItem from data
	 */
	private ListView lvBlackList;

	/**
	 * AdapterBlackList
	 */
	private AdapterBlackList adapter;
	/**
	 * list containt BlackListItem in data
	 */
	private List<BlackListItem> ListBlackItem = new ArrayList<BlackListItem>();

	/**
	 * variant this is size of ListBlackItem
	 */
	private int sizeList = 0;

	private int location = 0;

	/**
	 * id of row is selected after longClick
	 */
	private int idItem = 0;

	DatabaseHanler db = new DatabaseHanler(this);

	/**
	 * Broadcast to receive intent from dialog_setting_call_mode
	 */
	BroadcastReceiver broad = new BroadcastReceiver() {

		@Override
		public void onReceive(Context context, Intent intent) {

			if (db == null) {
				db = new DatabaseHanler(ActivityShowBlackListItem.this);
			}
			try {
				// update mode for BlackListitem
				int modeSms = ListBlackItem.get(location - 1).getMode() & 15;
				int modeCall = intent.getIntExtra("mode", 1) << 4;
				db.updateModeInBlackList(modeCall | modeSms, idItem);
				ListBlackItem = db.getBlackListItem(null, BlackListItem.MODE
						+ " != 0", null, null, null);
				
				adapter.update(ListBlackItem);
				
				
				
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.viewflipper_blacklist);
		getActionBar().setDisplayHomeAsUpEnabled(true);
		getFormWidget();
		initSetting();
		init();
		getEvent();
		startService();
	}

	public void init() {
		initViewFlipper();
		initBlackListItem();
	}

	public void initViewFlipper() {
		slide_in_left = AnimationUtils.loadAnimation(this,
				android.R.anim.slide_in_left);
		slide_out_right = AnimationUtils.loadAnimation(this,
				android.R.anim.slide_out_right);

		vflipMain.setInAnimation(slide_in_left);
		vflipMain.setOutAnimation(slide_out_right);
		currentPage = 0;
	}

	public void startService() {
		IntentFilter filter = new IntentFilter();
		filter.addAction(ApplicationConstants.BROADCAST_ACTION_CALL_SETTING);
		filter.addCategory(Intent.CATEGORY_DEFAULT);
		registerReceiver(broad, filter);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		switch (item.getItemId()) {
		case android.R.id.home:
			onBackPressed();
			break;
		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}

	public void getFormWidget() {
		// page blacklist
		imgAdd = (ImageView) findViewById(R.id.imgAddBlackListItem);
		edtAddPhoneNumber = (EditText) findViewById(R.id.edtAddPhoneNumer);
		edtAddPhoneNumber.setSelected(false);
		lvBlackList = (ListView) findViewById(R.id.lvBlackListItem);

		// view flipper
		vflipMain = (ViewFlipper) findViewById(R.id.vflipMain);
		btnBlackList = (Button) findViewById(R.id.btnBlackList);
		btnException = (Button) findViewById(R.id.btnException);

		// page exception list
		btnAddExceptionItem = (Button) findViewById(R.id.ibtnAddExceptionItem);
		edtAddPhNumer = (EditText) findViewById(R.id.edtAddPhNumer);
		lvExceptionListItem = (ListView) findViewById(R.id.lvExceptionListItem);

	}

	public void initBlackListItem() {
		ListBlackItem = db.getBlackListItem(null, BlackListItem.MODE + " != 0",
				null, null, null);
		sizeList = ListBlackItem.size();
		adapter = new AdapterBlackList(this, ListBlackItem);
		lvBlackList.setAdapter(adapter);
	}

	public void initExceptionListItem() {
		ListBlackItem = db.getBlackListItem(null, BlackListItem.MODE + " = 0",
				null, null, null);
		adapterException = new AdapterExceptionItem(
				ActivityShowBlackListItem.this, ListBlackItem);
		lvExceptionListItem.setAdapter(adapterException);
	}

	String text = "";

	public void getEvent() {
		setFunctionForBlackListPage();
		setFunctionForViewFlipper();
		setFunctionForExceptionPage();
	}

	public void setFunctionForBlackListPage() {
		edtAddPhoneNumber.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {

				text = edtAddPhoneNumber.getText().toString();

				if (text.equals("") || text.equals(null)) {
					ListBlackItem = db.getBlackListItem(null,
							BlackListItem.MODE + " != 0", null, null, null);
				} else {
					ListBlackItem = db.getBlackListItem(null, "("
							+ BlackListItem.NAME + " LIKE ?" + " OR "
							+ BlackListItem.PHONE_NUMBER + " LIKE ? " + ")"
							+ " AND " + BlackListItem.MODE + " != ?",
							new String[] { "%" + text + "%", "%" + text + "%",
									"0" }, null, null);
				}
				adapter.update(ListBlackItem);

			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {

			}

			@Override
			public void afterTextChanged(Editable s) {

			}
		});
		// event button add number to BlackListItem
		imgAdd.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				/**
				 * show dialog Add Phone Number
				 */
				dialog = new Dialog(context, R.style.cust_dialog);
				dialog.setContentView(R.layout.diaglog_add_phone_number);
				dialog.setTitle(context.getResources().getString(
						R.string.title_dialog_add_phone));

				final EditText edtName = (EditText) dialog
						.findViewById(R.id.edtName);
				final EditText edtPhone = (EditText) dialog
						.findViewById(R.id.edtPhone);
				String pattern = "^[0-9]*$";
				if (edtAddPhoneNumber.getText().toString().matches(pattern)) {
					edtPhone.setText(edtAddPhoneNumber.getText().toString());
				}
				Button btnSave = (Button) dialog.findViewById(R.id.btnSave);
				Button btnCancel = (Button) dialog.findViewById(R.id.btnCancel);
				Button btnChooseContact = (Button) dialog
						.findViewById(R.id.btnChooseContact);

				/**
				 * if edtPhone !="" then save into data
				 */
				btnSave.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						if (!edtPhone.getText().toString().equals("")) {
							BlackListItem blackListItem = new BlackListItem(
									edtPhone.getText().toString(), edtName
											.getText().toString(), sett.getDefaultModel());
							long insert = db.insertBlackListItem(blackListItem);
							Log.i(TAG,"id insert: " + insert);
							if(insert!=-1){
								ListBlackItem = db.getBlackListItem(null,
										BlackListItem.MODE + " != 0", null, null,
										null);
								adapter.update(ListBlackItem);
								Toast.makeText(
										context,
										context.getResources().getString(
												R.string.insert_success),
										Toast.LENGTH_SHORT).show();
							}
							else{
								Toast.makeText(
										context,
										context.getResources().getString(
												R.string.has_exit),
										Toast.LENGTH_SHORT).show();
							}
							
						} else {
							Toast.makeText(
									context,
									context.getResources().getString(
											R.string.insert_failed),
									Toast.LENGTH_SHORT).show();
						}
						dialog.dismiss();
					}
				});

				btnCancel.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						edtAddPhoneNumber.setText("");
						dialog.dismiss();
					}
				});

				btnChooseContact.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						Intent intent = new Intent(Intent.ACTION_PICK,
								ContactsContract.Contacts.CONTENT_URI);
						startActivityForResult(intent, PICK_CONTACT);
					}
				});

				dialog.show();
			}
		});

		lvBlackList.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {

				Intent intent = new Intent(ActivityShowBlackListItem.this,
						ActivityContactProfile.class);
				Bundle bundle = new Bundle();
				BlackListItem item = ListBlackItem.get(position);
				bundle.putSerializable("item", item);
				intent.putExtra("bundle", bundle);
				startActivity(intent);
				ActivityShowBlackListItem.this.finish();
			}
		});
		lvBlackList.setOnItemLongClickListener(new OnItemLongClickListener() {

			@Override
			public boolean onItemLongClick(AdapterView<?> parent, View view,
					int position, long id) {

				location = position + 1;
				idItem = ListBlackItem.get(position).getId();
				Intent intent = new Intent(ActivityShowBlackListItem.this,
						ActivityCallSetting.class);
				intent.putExtra("mode", ListBlackItem.get(position).getMode());
				intent.putExtra("postition", position);
				startActivity(intent);
				return false;
			}
		});
		// Tao endless load cho listview
		lvBlackList.setOnScrollListener(new OnScrollListener() {

			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {

			}

			@Override
			public void onScroll(AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {

				boolean loadMore = /* maybe add a padding */
				firstVisibleItem + visibleItemCount > totalItemCount - 15;

				if (loadMore && adapter.count < sizeList) {
					if ((40 + totalItemCount) < sizeList)
						adapter.count += 40;
					else {
						adapter.count += sizeList - totalItemCount;
					}
					adapter.notifyDataSetChanged();
				}
			}
		});
	}

	public void setFunctionForViewFlipper() {
		btnBlackList.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				btnBlackList.setBackgroundDrawable(getResources().getDrawable(
						R.drawable.frame_press));
				btnException.setBackgroundDrawable(getResources().getDrawable(
						R.drawable.frame));
				selectPage(0);
			}
		});

		btnException.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				btnException.setBackgroundDrawable(getResources().getDrawable(
						R.drawable.frame_press));
				btnBlackList.setBackgroundDrawable(getResources().getDrawable(
						R.drawable.frame));
				selectPage(1);
			}
		});
	}

	public void setFunctionForExceptionPage() {
		
		edtAddPhNumer.addTextChangedListener(new TextWatcher() {
			
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				
			}
			
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				
			}
			
			@Override
			public void afterTextChanged(Editable s) {
				text = s.toString().trim();

				if (text.equals("") || text.equals(null)) {
					ListBlackItem = db.getBlackListItem(null,
							BlackListItem.MODE + " = 0", null, null, null);
				} else {
					ListBlackItem = db.getBlackListItem(null, "("
							+ BlackListItem.NAME + " LIKE ?" + " OR "
							+ BlackListItem.PHONE_NUMBER + " LIKE ? " + ")"
							+ " AND " + BlackListItem.MODE + " = ?",
							new String[] { "%" + text + "%", "%" + text + "%",
									"0" }, null, null);
				}
				
				adapterException = new AdapterExceptionItem(ActivityShowBlackListItem.this, ListBlackItem);
				lvExceptionListItem.setAdapter(adapterException);

			}
		});
		
		btnAddExceptionItem.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				/**
				 * show dialog Add Phone Number
				 */
				dialog = new Dialog(context, R.style.cust_dialog);
				dialog.setContentView(R.layout.diaglog_add_phone_number);
				dialog.setTitle(context.getResources().getString(
						R.string.title_dialog_add_phone));

				final EditText edtName = (EditText) dialog
						.findViewById(R.id.edtName);
				final EditText edtPhone = (EditText) dialog
						.findViewById(R.id.edtPhone);
				String pattern = "^[0-9]*$";
				if (edtAddPhoneNumber.getText().toString().matches(pattern)) {
					edtPhone.setText(edtAddPhoneNumber.getText().toString());
				}
				Button btnSave = (Button) dialog.findViewById(R.id.btnSave);
				Button btnCancel = (Button) dialog.findViewById(R.id.btnCancel);
				Button btnChooseContact = (Button) dialog
						.findViewById(R.id.btnChooseContact);

				/**
				 * if edtPhone !="" then save into data
				 */
				btnSave.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						if (!edtPhone.getText().toString().equals("")) {
							BlackListItem blackListItem = new BlackListItem(
									edtPhone.getText().toString(), edtName
											.getText().toString(), 0);
							if(db.insertBlackListItem(blackListItem)>0){
								ListBlackItem = db.getBlackListItem(null,
										BlackListItem.MODE + " = 0", null, null,
										null);
								adapterException = new AdapterExceptionItem(
										ActivityShowBlackListItem.this,
										ListBlackItem);
								lvExceptionListItem.setAdapter(adapterException);
								Toast.makeText(
										context,
										context.getResources().getString(
												R.string.insert_success),
										Toast.LENGTH_SHORT).show();
							}
							else{
								Toast.makeText(
										context,
										context.getResources().getString(
												R.string.has_exit),
										Toast.LENGTH_SHORT).show();
							}
						} else {
							Toast.makeText(
									context,
									context.getResources().getString(
											R.string.insert_failed),
									Toast.LENGTH_SHORT).show();
						}
						dialog.dismiss();
					}
				});

				btnCancel.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						edtAddPhoneNumber.setText("");
						dialog.dismiss();
					}
				});

				btnChooseContact.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						Intent intent = new Intent(Intent.ACTION_PICK,
								ContactsContract.Contacts.CONTENT_URI);
						startActivityForResult(intent, PICK_CONTACT_EXCEPTION);
					}
				});

				dialog.show();
			}
		});
	
		lvExceptionListItem.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				
				if(ListBlackItem == null || ListBlackItem.equals(null) || ListBlackItem.size() ==0){
					return;
				}
				
				final BlackListItem item = ListBlackItem.get(position); 
				
				/**
				 * show dialog Add Phone Number
				 */
				dialog = new Dialog(context, R.style.cust_dialog);
				dialog.setContentView(R.layout.diaglog_add_phone_number);
				dialog.setTitle(context.getResources().getString(
						R.string.title_dialog_add_phone));

				final EditText edtName = (EditText) dialog
						.findViewById(R.id.edtName);
				final EditText edtPhone = (EditText) dialog
						.findViewById(R.id.edtPhone);
				
				edtName.setText(item.getName());
				edtPhone.setText(item.getPhoneNumber());
				
				
				Button btnSave = (Button) dialog.findViewById(R.id.btnSave);
				Button btnCancel = (Button) dialog.findViewById(R.id.btnCancel);
				Button btnChooseContact = (Button) dialog
						.findViewById(R.id.btnChooseContact);
				btnChooseContact.setText(ActivityShowBlackListItem.this.getResources().getString(R.string.delete));
				
				btnSave.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						item.setPhoneNumber(edtPhone.getText().toString());
						item.setName(edtName.getText().toString());
						db.updateBlackListItem(item, BlackListItem.ID + " = " + item.getId() , null);
						adapterException.notifyDataSetChanged();
						dialog.dismiss();
					}
				});
				
				btnCancel.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						dialog.dismiss();
					}
				});
				
				btnChooseContact.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						db.deleteBlackListItem(BlackListItem.ID + " = "+item.getId(), null);
						ListBlackItem.remove(item);
						adapterException.notifyDataSetChanged();
						dialog.dismiss();
					}
				});
				
				dialog.show();
				
			}
			
		});
	
	}

	/**
	 * Go to the new page of vflipmain
	 * 
	 * @param page
	 *            : position that you want to transfer
	 */
	void selectPage(int page) {

		currentPage = page;
		if(dialog!= null && !dialog.equals(null) ){
			dialog.dismiss();
		}

		switch (page) {
		case 0:
			initBlackListItem();
			break;
		case 1:
			initExceptionListItem();
			break;
		default:
			break;
		}

		vflipMain.setDisplayedChild(page);
	}

	@Override
	public void onBackPressed() {
		Intent in = new Intent(ActivityShowBlackListItem.this,
				ActivityDashboard.class);
		startActivity(in);
		finish();
	}

	@Override
	protected void onResume() {

		super.onResume();
	}

	@Override
	protected void onDestroy() {

		super.onDestroy();
		unregisterReceiver(broad);
	}

	@Override
	public void onActivityResult(int reqCode, int resultCode, Intent data) {
		super.onActivityResult(reqCode, resultCode, data);

		switch (reqCode) {
		case (PICK_CONTACT):
			if (resultCode == Activity.RESULT_OK) {
				addNewItemBlackListFromContact(data);

			}
			if (dialog != null && !dialog.equals(null) && dialog.isShowing()) {
				dialog.dismiss();
			}
			break;
		case (PICK_CONTACT_EXCEPTION):
			if (resultCode == Activity.RESULT_OK) {
				addNewExceptionFromContact(data);

			}
			if (dialog != null && !dialog.equals(null) && dialog.isShowing()) {
				dialog.dismiss();
			}
			break;
		}
	}

	void addNewItemBlackListFromContact(Intent data) {
		try{
			Uri contactData = data.getData();
			Cursor c = getContentResolver().query(contactData, null, null, null,
					null);
			if (c.moveToFirst()) {
				String id = c.getString(c
						.getColumnIndexOrThrow(ContactsContract.Contacts._ID));

				String hasPhone = c
						.getString(c
								.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));

				if (hasPhone.equalsIgnoreCase("1")) {
					Cursor phones = getContentResolver().query(
							ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
							null,
							ContactsContract.CommonDataKinds.Phone.CONTACT_ID
									+ " = " + id, null, null);
					phones.moveToFirst();
					String phn_no = phones
							.getString(phones.getColumnIndex("data1"));
					try {
						phn_no = phn_no.replaceAll("-", "");
						phn_no = phn_no.replaceAll("_", "");
						phn_no = phn_no.replaceAll("(", "");
						phn_no = phn_no.replaceAll(")", "");
					} catch (Exception e) {
						e.printStackTrace();
					}
					String name = c.getString(c
							.getColumnIndex(StructuredPostal.DISPLAY_NAME));
					BlackListItem blackListItem = new BlackListItem(phn_no, name, sett.getDefaultModel());
					db.insertBlackListItem(blackListItem);
					ListBlackItem = db.getBlackListItem(null, BlackListItem.MODE
							+ " != 0", null, null, null);
					adapter.update(ListBlackItem);
					Toast.makeText(
							context,
							context.getResources().getString(
									R.string.insert_success), Toast.LENGTH_SHORT)
							.show();
				} else {
					Toast.makeText(
							context,
							context.getResources()
									.getString(R.string.insert_failed),
							Toast.LENGTH_SHORT).show();
				}

			} else {
				Toast.makeText(context,
						context.getResources().getString(R.string.insert_failed),
						Toast.LENGTH_SHORT).show();
			}
		}catch(Exception e){
			Toast.makeText(context,
					context.getResources().getString(R.string.insert_failed),
					Toast.LENGTH_SHORT).show();
			e.printStackTrace();
		}
		
	}

	void addNewExceptionFromContact(Intent data) {
		try{
			Uri contactData = data.getData();
			Cursor c = getContentResolver().query(contactData, null, null, null,
					null);
			if (c.moveToFirst()) {
				String id = c.getString(c
						.getColumnIndexOrThrow(ContactsContract.Contacts._ID));

				String hasPhone = c
						.getString(c
								.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));

				if (hasPhone.equalsIgnoreCase("1")) {
					Cursor phones = getContentResolver().query(
							ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
							null,
							ContactsContract.CommonDataKinds.Phone.CONTACT_ID
									+ " = " + id, null, null);
					phones.moveToFirst();
					String phn_no = phones
							.getString(phones.getColumnIndex("data1"));
					try {
						phn_no = phn_no.replaceAll("-", "");
						phn_no = phn_no.replaceAll("_", "");
						phn_no = phn_no.replaceAll("(", "");
						phn_no = phn_no.replaceAll(")", "");
					} catch (Exception e) {
						e.printStackTrace();
					}
					String name = c.getString(c
							.getColumnIndex(StructuredPostal.DISPLAY_NAME));
					BlackListItem blackListItem = new BlackListItem(phn_no, name,
							0);
					db.insertBlackListItem(blackListItem);
					ListBlackItem = db.getBlackListItem(null, BlackListItem.MODE
							+ " = 0", null, null, null);
					adapterException = new AdapterExceptionItem(ActivityShowBlackListItem.this, ListBlackItem);
					lvExceptionListItem.setAdapter(adapterException);
					
					
					Toast.makeText(
							context,
							context.getResources().getString(
									R.string.insert_success), Toast.LENGTH_SHORT)
							.show();
				} else {
					Toast.makeText(
							context,
							context.getResources()
									.getString(R.string.insert_failed),
							Toast.LENGTH_SHORT).show();
				}

			} else {
				Toast.makeText(context,
						context.getResources().getString(R.string.insert_failed),
						Toast.LENGTH_SHORT).show();
			}

		}catch(Exception e){
			Toast.makeText(context,
					context.getResources().getString(R.string.insert_failed),
					Toast.LENGTH_SHORT).show();
			e.printStackTrace();
		}
	}

	void initSetting(){
		if(db == null){
			db = new DatabaseHanler(ActivityShowBlackListItem.this);
		}
		sett = db.getSetting(null);
	}
	
}
